Title: SQL W3S (By-BKK) / 124 SQL Quick Ref
Tags: Obsidian_to_Anki

Q: What does SQL stand for?
A: Structured Query Language

Q: What is the purpose of SQL?
A: SQL is used to communicate with relational databases

Q: Which keyword is used to select data from a table?
A: SELECT

Q: SELECT retrieves data from a table
A: Which SQL keyword is used to fetch data?

Q: True/False: SQL can be used to update records in a database
A: True

Q: What keyword is used to change the data in existing records?
A: UPDATE

Q: UPDATE modifies existing records
A: Which SQL statement updates existing rows in a table?

Q: DELETE removes rows from a table
A: Which SQL statement deletes rows?

Q: What keyword is used to add new records to a table?
A: INSERT INTO

Q: INSERT INTO adds new rows
A: Which SQL statement inserts new data?

Q: True/False: DROP TABLE deletes just the records but keeps the table structure
A: False

Q: What does DROP TABLE do?
A: Removes the entire table, including its structure

Q: Which SQL statement creates a new table?
A: CREATE TABLE

Q: CREATE TABLE defines a new table
A: Which statement is used to make a table?

Q: How do you add a column to an existing table?
A: ALTER TABLE table_name ADD column_name datatype

Q: How do you remove a column from an existing table?
A: ALTER TABLE table_name DROP COLUMN column_name

Q: True/False: ALTER TABLE can change the table structure
A: True

Q: What SQL keyword is used to sort query results?
A: ORDER BY

Q: ORDER BY sorts results
A: Which SQL clause arranges records?

Q: How do you select unique values in a table?
A: SELECT DISTINCT

Q: SELECT DISTINCT fetches unique values
A: Which SQL keyword is used for non-duplicate results?

Q: What is the meaning of WHERE in a SQL query?
A: Filters records based on a condition

Q: WHERE filters rows by condition
A: Which SQL clause limits records?

Q: How do you combine two tables with matching columns?
A: Use JOIN

Q: JOIN merges data from two tables
A: Which SQL operation links tables by commons columns?

Q: What is the difference between INNER JOIN and LEFT JOIN?
A: INNER JOIN returns only matching rows. LEFT JOIN returns all rows from the left table plus matches from the right table.

Q: True/False: You can group rows with GROUP BY in SQL
A: True

Q: What do you use GROUP BY for in SQL?
A: To arrange rows with the same values into groups

Q: GROUP BY organizes rows
A: Which SQL clause groups related records?

Q: How do you filter grouped results in SQL?
A: HAVING

Q: HAVING filters groups after GROUP BY
A: Which SQL clause restricts groups?

Q: What is the syntax for selecting records with values between two numbers?
A: WHERE column_name BETWEEN value1 AND value2

Q: True/False: LIKE is used for pattern matching in SQL
A: True

Q: What is the purpose of SQL LIKE?
A: To search for a specified pattern in a column

Q: LIKE matches patterns in strings
A: Which SQL operator helps find words containing a certain letter?

Q: How do you select records with a value from a list?
A: WHERE column_name IN (value1, value2, …)

Q: IN selects records from a set
A: Which SQL operator finds values in a list?

Q: Which SQL keyword is used to remove all rows from a table?
A: TRUNCATE TABLE

Q: TRUNCATE TABLE clears all rows
A: Which command deletes all data but keeps the structure?

Q: What does the UNION operator do in SQL?
A: Combines results from two SELECT queries, removing duplicates

Q: UNION ALL includes all results, even duplicates
A: What does UNION ALL do compared to UNION?

Q: Which statement creates a database?
A: CREATE DATABASE database_name

Q: CREATE DATABASE makes a new database
A: Which SQL statement is used to make a database?

Q: How to create an index on a table column?
A: CREATE INDEX index_name ON table_name (column_name)

Q: CREATE INDEX speeds up searches
A: What SQL statement creates a search index?

Q: What are aliases used for in SQL?
A: To give tables or columns temporary names

Q: AS assigns a temporary name
A: Which keyword makes an alias in SQL?

Q: What does SELECT * do?
A: Selects all columns from a table

Q: SELECT * retrieves all data
A: What SQL query gets every field from a table?

Q: How do you select the top N rows from a table?
A: SELECT TOP number column_name FROM table_name

Q: SELECT TOP fetches a limited number of rows
A: Which clause restricts the number of rows returned?

Q: How do you create a view in SQL?
A: CREATE VIEW view_name AS SELECT …

Q: CREATE VIEW defines a virtual table
A: Which SQL statement creates a saved query?

Q: How do you backup a database?
A: BACKUP DATABASE database_name

Q: BACKUP DATABASE creates a copy
A: Which SQL command saves a copy of the database?

Q: What is the role of EXISTS in SQL?
A: Checks if a subquery returns any results

Q: EXISTS tests for subquery results
A: Which keyword is used to check if records exist?

Q: Which SQL command removes a database?
A: DROP DATABASE database_name

Q: DROP DATABASE deletes the database
A: Which statement erases an entire database?

Q: What command is used to comment in SQL?
A: -- comment text

Q: -- is used for writing comments
A: Which symbol starts a comment in SQL?

Q: How do you create a unique index on a table?
A: CREATE UNIQUE INDEX index_name ON table_name (column_name)

Q: CREATE UNIQUE INDEX prevents duplicate values
A: Which index type enforces uniqueness?

Q: What does SELECT INTO do?
A: Copies data into a new table

Q: SELECT INTO creates a table from another table's rows
A: Which SQL statement copies data into a new table?

Q: What is the function of SQL constraints?
A: Rules enforced on data columns

Q: Constraints define data rules
A: What are rules that limit the type of data in SQL?

Q: How can you set default values in a column?
A: DEFAULT

Q: DEFAULT specifies an initial value
A: Which SQL keyword is used for initial values in columns?

Q: What does PRIMARY KEY do?
A: Uniquely identifies a row in a table

Q: PRIMARY KEY sets a unique identifier
A: Which SQL constraint enforces uniqueness for rows?

Q: What is a FOREIGN KEY in SQL?
A: A key that links two tables together

Q: FOREIGN KEY creates relationships between tables
A: Which SQL constraint connects tables by columns?

Q: How do you delete records from a table?
A: Use